<template>
    <view v-if="Index == 0">
        <view class="aucoachbox" v-for="(item, index) in list" :key="index" @click="goNext(item.state,item)">
            <view class="left">
                <image class="icon" :src="item.icon" mode="widthFix"></image>
                <view class="name">{{ item.name }}</view>
                <view class="state" :style="{color:textColor[item.state].color,backgroundColor:textColor[item.state].bg}">{{ textColor[item.state].text}}</view>
            </view>
            <image class="rimg" :src="item.rightimg" mode="widthFix"></image>
        </view>
    </view>
    <view v-else>
        <view class="aucoachbox" v-for="(item, index) in list1" :key="index" @click="navNext(item)">
            <view class="left">
                <!-- <image class="icon" :src="item.icon" mode="widthFix"></image> -->
                <view class="name">{{ item.name }}</view>
                <!-- <view class="state" :style="{color:textColor[item.state].color,backgroundColor:textColor[item.state].bg}">{{ textColor[item.state].text}}</view> -->
            </view>
            <image class="rimg" :src="item.rightimg" mode="widthFix"></image>
        </view>
        <!-- ,{
                icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/171564870677163.png',
                name:'核销',
                rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                path: '/pages/court/writeOff',
            } -->
    </view>
</template>
<script>
export default {
    data() {
        return {
            list: [
                // {
                //     icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/17156486778731487.png',
                //     name: '实名认证',
                //     rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                //     path: '/pages/user/real_name',
                //     state: 99,
                // },
                {
                    icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/171564870677163.png',
                    name: '教练入驻',
                    rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                    path: '/pages/teacher/Settled',
                    state: 99,
                },
                {
                    icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1715648698051818.png',
                    name: '商家入驻',
                    rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                    path: '/pages/user/real_store?index=0',
                    state: 99,
                },
            ],
            list1:[{
                icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/171564870677163.png',
                name:'管理门店',
                rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                path: '/pages/user/real_store?index=1',
            },{
                icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/171564870677163.png',
                name:'场地管理',
                rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                path: '/pages/teacher/increase',
            },{
                icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/171564870677163.png',
                name:'场地订单',
                rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                path: '/pages/ball/ball_list_user',
            },{
                icon: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/171564870677163.png',
                name:'门店收益',
                rightimg: 'https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711011951088796.png',
                path: '/pages/user/merchant',
            }],
            shopstate: 0,
            techstate: 0,
            namestate: false,
            textColor: {
                '0': {
                    color: '#E7A127',
                    text: '审核中',
                    bg: '#FFF4E0'
                },
                '-1': {
                    color: '#E72F27',
                    text: '认证失败，请重新认证',
                    bg: '#FEF3F2'
                },
                '1': {
                    color: '#2BA139',
                    text: '已认证',
                    bg: '#E5FFE8'
                },
                '99': {
                    color: '#666666',
                    text: '未认证',
                    bg: '#F2F2F2'
                },
            },
            Index:0,
            BarTitle:'',
            shopId:null,
            IsOpenAuth:0,
        }
    },
    onLoad(e){
        this.Index = e.index || 0
        if(this.Index == 0){
            this.BarTitle ='认证'
        }else{
            this.BarTitle ='商家管理'
            this.apiGetStatus(2)
        }
        this.appauth()
        uni.setNavigationBarTitle({
			title: this.BarTitle,
			success: function () {
			},
			fail: function (err) {
			}
		});
    },
    async onShow() {
        this.getAllStatus()
    },
    methods: {
    async appauth(){
        let res =await this.$api.post('common/appauth')
        if(res.code == 0){
            this.IsOpenAuth = res.data.IsOpenAuth
        }
    },
        goNext(state,item){
            if(state == 99 || state == -1){
                this.nav_to(item.path)
            }
        },
        getAllStatus() {
            if(this.IsOpenAuth == 0){
                for (let i = 0; i < this.list.length; i++) {
                    if(this.list[i].name == '商家入驻'){
                        this.list.splice(i,1)
                    }

                }
            }
            for (let i = 0; i < this.list.length; i++) {
                this.apiGetStatus(i).then(res => {
                    this.list[i].state = res
                })

            }
        },
        async apiGetStatus(e) {
            let url = e == -1 ? 'User/IsTrueName' : e == 0 ? 'Technicians/Get' : 'Shops/MyShop'
            let type = 99
            await this.$api.post(url).then(res => {
                // console.log(res, 'res');
                if (e == -1) {
                    type = res?.data ? 1 : 99
                } else if(e == 0){
                    type = res?.data == '' ? 99:res?.data.Status
                }else{
                    type = res?.data == null ? 99:res?.data.Status
                    this.shopId = res?.data?.ID || null
                }
            })
            return type

        },
        navNext(item){
            let url = item.name=='场地管理'?`${item.path}?shopId=${this.shopId}`:item.name=='场地订单'?`${item.path}?shopId=${this.shopId}&index=4&title=场地订单`:item.path
            this.nav_to(url)
        },
    },
    onReady() {
        uni.setNavigationBarColor({
            frontColor: '#000000',
            backgroundColor: '#ffffff',
            animation: {
                duration: 400,
                timingFunc: 'easeIn'
            }
        })
    },
}
</script>
<style lang="less">
page {
    background-color: #F6F6F6;
}

.aucoachbox {
    width: 100%;
    height: 108rpx;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 32rpx;
    box-sizing: border-box;
    margin: 16rpx 0;

    .left {
        display: flex;
        align-items: center;

        .icon {
            width: 48rpx;
            height: 48rpx;
            margin-right: 8rpx;
        }

        .name {
            font-size: 32rpx;
            color: #333333;
        }

        .state {
            padding: 4rpx 12rpx;
            font-size: 24rpx;
            border-radius: 4rpx;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 12rpx;
        }

        .bg1 {
            color: #666666;
            background-color: #F2F2F2;
        }

        .bg2 {
            color: #E7A127;
            background-color: #FFF4E0;
        }

        .bg3 {
            color: #2BA139;
            background-color: #E5FFE8;
        }
    }

    .rimg {
        width: 32rpx;
        height: 44rpx;
    }
}
</style>